package com.pan.demo.controller;

import com.pan.demo.entity.Animal;
import com.pan.demo.service.DemoService;
import com.pan.demo.utils.SimpleJson;
import com.pan.framework.anno.common.MyInject;
import com.pan.framework.anno.controller.MyController;
import com.pan.framework.anno.controller.MyGetMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@MyController(name = "demoController",path = "/demo")
public class DemoController {

    @MyInject(name = "simpleJson")
    private SimpleJson simpleJson;

    @MyInject(name = "demoService")
    private DemoService service;

    @MyGetMapping(path = "/queryAnimal")
    public String queryAnimal(HttpServletResponse response) throws IOException {
        response.setContentType("text/json");
        response.setCharacterEncoding("utf-8");
        List<Animal> animals = service.queryAnimal();
        String json = simpleJson.mapperList(animals);
//        System.out.println(json);
        return json;
    }

    @MyGetMapping(path = "/queryOne")
    public String queryOne() throws Exception {
        Animal animal = service.queryOneAnimal();
        String json = simpleJson.mapper(animal);
//        System.out.println(json);
        return json;

    }


    @MyGetMapping(path="/test")
    public String test(){
        return "{\"message\": \"success\"}";
    }
}
